package com.uidt.project.ptsj.controller;

import com.uidt.common.utils.StringUtils;
import com.uidt.common.utils.poi.ExcelUtil;
import com.uidt.framework.aspectj.lang.annotation.Log;
import com.uidt.framework.aspectj.lang.enums.BusinessType;
import com.uidt.framework.redis.RedisCache;
import com.uidt.framework.web.controller.BaseController;
import com.uidt.framework.web.domain.AjaxResult;
import com.uidt.framework.web.page.TableDataInfo;
import com.uidt.project.ptsj.domain.Rank;
import com.uidt.project.ptsj.service.IRankService;
import com.uidt.project.ptsj.service.IWeChatApiService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 红黑榜Controller
 * 
 * @author uidt
 * @date 2024-08-22
 */
@RestController
@RequestMapping("/ptsj/weChat")
public class WeChatController extends BaseController {
    @Autowired
    private IWeChatApiService weChatApiService;

    @Autowired
    private RedisCache redisCache;

    /**
     * 获取红黑榜小程序跳转链接
     */
    @GetMapping("/getWeChatUrl")
    public AjaxResult list(Rank rank) {
        String url = "";
        try {
            url = redisCache.getCacheObject("PTSJ:WECHAT:URL");
            if(StringUtils.isEmpty(url)) {
                String accessToken = weChatApiService.getAccessToken();
                if (StringUtils.isNotEmpty(accessToken)) {
                    url = weChatApiService.getUrllink(accessToken);
                    if (StringUtils.isNotEmpty(url)) {
                        redisCache.setCacheObject("PTSJ:WECHAT:URL", url, 6, TimeUnit.HOURS);
                    }
                }
            }

        } catch (Exception e) {
            return AjaxResult.success("",url);
        }
        return AjaxResult.success("",url);
    }

}


